import { Effect, ImmerReducer } from "@/.umi/plugin-dva/connect"
import { getOrder, getStateOrder } from "@/service/order"
export interface IOrdertel {
    name: string,
    tel: string,
    province: string,
    city: string,
    county: string,
    addressDetail: string,
    orderid: string,
    userid: string,
    status: number,
    proname: string,
    proid: string,
    originprice: number,
    img1: string,
    discount: number,
    num: number,
    time: string
}
export interface IListC1 {
    tel: string,
    data: {
        cartid: string,
        username: string,
        tel: number,
        proid: string,
        proname: string,
        img1: string,
        originprice: number,
        discount: number,
        sales: number,
        stock: number,
        category: string,
        brand: string,
    }
}
export interface ICart {
    namespace: 'order',
    state: {
        orderList: Array<IOrdertel>
        orderList1: Array<IOrdertel>
    },
    effects: {
        getOrderW: Effect
        getOrderW1: Effect
    },
    reducers: {
        UPDATA_ORDER: ImmerReducer
        UPDATA_ORDER1: ImmerReducer
    }
}
const GetCartList: ICart = {
    namespace: 'order',
    state: {
        orderList: [],
        orderList1: []
    },
    effects: {
        *getOrderW({ payload }, { call, put }) {
            const res = yield call(getOrder, payload)
            yield put({
                type: 'UPDATA_ORDER',
                payload: res.data
            })
        },
        *getOrderW1({ payload }, { call, put }) {
            const res = yield call(getStateOrder, payload)
            yield put({
                type: 'UPDATA_ORDER',
                payload: res.data
            })
        },
    },
    reducers: {
        UPDATA_ORDER(state, action) {
            state.orderList = action.payload
            // console.log(state.orderList,123);
        },
        UPDATA_ORDER1(state, action) {
            state.orderList1 = action.payload
            // console.log(state.cartList1,123);
        }
    }
}

export default GetCartList